package com.dudsbury.other;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import java.awt.print.*;

import com.dudsbury.gui.ReportScreen;

public class Printer implements Printable, ActionListener {
	
	
	//Pass down needed to print string
	//static String text = ReportScreen.Text;

	 String text;
    public Printer(String text2) {
    	
    	 text = text2;
    	System.out.println(text2);
    	
    	this.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, null));
		// TODO Auto-generated constructor stub
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		// TODO Auto-generated method stub
		  PrinterJob job = PrinterJob.getPrinterJob();
	         job.setPrintable(this);
	         boolean ok = job.printDialog();
	         if (ok) {
	             try {
	                  job.print();
	             } catch (PrinterException ex) {
	              /* The job did not successfully complete */
	             }
	         }
	}

	@Override
	public int print(Graphics g, PageFormat pf, int page)
			throws PrinterException {
		
		 if (page > 0) { /* We have only one page, and 'page' is zero-based */
	            return NO_SUCH_PAGE;
	        }

	        /* User (0,0) is typically outside the imageable area, so we must
	         * translate by the X and Y values in the PageFormat to avoid clipping
	         */
	        Graphics2D g2d = (Graphics2D)g;
	        g2d.translate(pf.getImageableX(), pf.getImageableY());

	        /* Now we perform our rendering */
	        g.drawString(text, 100, 100);
	        
	        
	        /* tell the caller that this page is part of the printed document */
	        return PAGE_EXISTS;
		// TODO Auto-generated method stub
		
	}

}
